﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using PiscoSourDominio;
using PiscoSourSOAPRestServices.Persistencia;
using Dapper;

namespace PiscoSourRESTServices.Persistencia
{
    public class CartaLocalDAO
    {
        public Carta_Local ObtenerCartaLocal(string codigo)
        {
            using (var sqlConnection = ConnectionFactory.GetConnection())
            {
                sqlConnection.Open();
                const string sqlQuery = "select * from psr_carta_local where idCodCarta=@idCodCarta";
                var cartaLocal = sqlConnection.Query<Carta_Local>(sqlQuery, new { idCodCarta = codigo }).SingleOrDefault<Carta_Local>();

                sqlConnection.Close();

                return cartaLocal;
            }
        }

        public IEnumerable<Carta_Local> ListarRestaurante()
        {
            using (var sqlConnection = ConnectionFactory.GetConnection())
            {
                sqlConnection.Open();
                var sqlQuery = string.Format(@"Select * from psr_carta_local");
                var result = sqlConnection.Query<Carta_Local>(sqlQuery);
                sqlConnection.Close();
                return result;
            }
        }
    }
}